﻿using System;
using System.Collections.Generic;
using System.Linq;
using DTO;
using System.Data;

namespace DAO
{
    public class CaDAO
    {
     
        public static bool insertca(CaDTO ca)
        {
            DataProvider d = new DataProvider();
            String strSQL = "INSERT INTO dbo.AL_Shift(ShiftName, StartTime, EndTime)";
            strSQL += " VALUES (N'" + ca._str + "', "+DateTime.Now.ToString()+", "+DateTime.Now.ToString()+")";
            d.ExecuteQuery(strSQL);
            return true;

        }
        public DataTable showdata()
        {
            DataProvider d = new DataProvider();
            string str = "SELECT * FROM dbo.AL_Shift";
            DataTable dt=d.ExecuteQuery(str);
            return dt;
        }
        public static List<CaDTO> getall()
        {
            DataProvider d = new DataProvider();
            String strSQL = "SELECT * FROM dbo.AL_Shift";
            DataTable dt = d.ExecuteQuery(strSQL);

            List<CaDTO> lstca = new List<CaDTO>();
            foreach (DataRow dr in dt.Rows)
            {
                CaDTO hs = new CaDTO();
                hs._id = (int)dr["ShiftID"];
                hs._str = dr["ShiftName"].ToString();
                lstca.Add(hs);
            }
            return lstca;

        }
    }
}
